package com.ruubypay.biz.utils.file;

import org.jooq.lambda.Unchecked;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Comparator;

/**
 * java 删除所有的资源文件和文件夹
 * @author chenhaiyang
 */
public class DelAllFile {

    private static Logger logger = LoggerFactory.getLogger(DelAllFile.class);
    /**
     * 递归删除
     * @param folderPath 文件路径 (只删除此路径的最末路径下所有文件和文件夹)
     */
    public static void delFolder(String folderPath) {
        try {
            Files.walk(Paths.get(folderPath), FileVisitOption.FOLLOW_LINKS)
                    .sorted(Comparator.reverseOrder())
                    .forEach(Unchecked.consumer(Files::delete));
        } catch (IOException e) {
            logger.error(e.getMessage(),e);
        }
    }

}
